package uit.mmt02.activity;

import uit.mmt02.R;
import uit.mmt02.gmail.GmailControl;
import uit.mmt02.mailControl.YahooControl;
import uit.mmt02.share.showToast;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class newmailActivity extends Activity
{
	final static String KEY_SUB = "SUB";
	final static String KEY_TO = "TO";
	final static String KEY_BODY = "BODY";
	showToast d;
	EditText txt_sub, txt_body;
	String tag = "newmailActivity";
	
	AutoCompleteTextView txt_to;
	
	protected void onCreate(Bundle savedInstanceState) 
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		d = new showToast(getBaseContext());
		setContentView(R.layout.newmail);
		
		//
		Bundle bundle = getIntent().getExtras();
		
		//
		if(bundle.size() >0)
		{
			Log.v("newmailaA", "getbundle");
			txt_sub = (EditText)findViewById(R.id.txt_newmail_sub);
			txt_body = (EditText)findViewById(R.id.txt_newmail_body);
			txt_to = (AutoCompleteTextView)findViewById(R.id.txt_newmail_to);
			
			txt_to.setText(bundle.getString(KEY_TO));
			txt_sub.setText("Re: " + bundle.getString(KEY_SUB));
			txt_body.setText("-----------\n " + bundle.getString(KEY_BODY));
		}
	}
	
	public void btn_onClick(View v)
	{
		Button btn = (Button)v;
		switch (btn.getId()) {
		case R.id.btn_newmail_send:
			d.showmess("send");
			String str = Environment.getExternalStorageDirectory().getAbsolutePath()+"/Esafe2.pk";
			String []chuoi = new String[]{str};
			GmailControl g = new GmailControl("sonntuit@gmail.com", "sacrifices");
			g.send("123", "456", "nung286@gmail.com", chuoi);
			
//			YahooControl y = new YahooControl("thaithao07520323@yahoo.com", "abc@123456");
//			y.send("123", "456", "nung286@gmail.com", null);
			d.showmess("send thanh cong");
			
			break;
		case R.id.btn_newmail_mahoa:
			d.showmess("ma hoa");
			break;
		case R.id.btn_newmail_saveDraft:
			d.showmess("save nhap");
			break;
		case R.id.btn_newmail_huy:
			d.showmess("Huy");
			break;
		case R.id.btn_Mnewmail:
			openOptionsMenu();
			break;

		default:
			break;
		}
	}
	

	//khoi tao menu send
	@Override
	public boolean onCreateOptionsMenu(Menu menu) 
	{
		// TODO Auto-generated method stub
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu_newmail, menu);
		return super.onCreateOptionsMenu(menu);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) 
	{
		// TODO Auto-generated method stub
		switch (item.getItemId()) 
		{
		case R.id.item_send:
			d.showmess("send123");
			Log.v(tag, "log1");Log.v(tag, "log1");
//			GmailControl g = new GmailControl("sonntuit@gmail.com", "sacrifices");
//			d.showmess("rrrrrrrrrrrrrr");
//			showToast sst = new showToast(getBaseContext());
//			sst.showmess("aaaaaaaaaaaaaaaaaaaaaaaaaaa");
//			YahooControl y = new YahooControl("thaithao07520323@yahoo.com", "abc@123456");
//			y.send("123", "456", "nung286@gmail.com", null);
//			d.showmess("send thanh cong");
			break;
		case R.id.item_add:
			d.showmess("add bb cc");
			break;
		case R.id.item_attach:
			d.showmess("attach");
			break;
		case R.id.item_save:
			d.showmess("savve");
			break;
		case R.id.item_discard:
			d.showmess("discard");
			break;
		case R.id.item_more:
			d.showmess("more");
			break;

		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}

}
